{##
 # TODO: description
 #
 # @copyright  Copyright (c) 2010-2011 The Fajr authors (see AUTHORS).
 #             Use of this source code is governed by a MIT license that can be
 #             found in the LICENSE file in the project root directory.
 # @author     TODO
 #}
{% extends "layout/studium.xhtml" %}
{% block title %}Prihlásenie na skúšky{% endblock %}
{% block application_content %}
{% import "macros/decorators.xhtml" as decorators %}
{% import "macros/table.xhtml" as table %}
{% import "macros/studium.xhtml" as studiumMacros %}
{{ parent() }}
{% set tabContent %}

{% macro tabulkaTermin(row, prihlas, studium, zapisnyList, action) %}
    {% url link for {'action': action,
                     'studium': studium,
                     'list': zapisnyList,
                     'predmet': row.predmetIndex,
                     'termin': row.index} %}
    {% import "macros/decorators.xhtml" as decorators %} 
    {% set title %}
      {{decorators.span(row.predmet,"table_box_title")}}
    {% endset %}
    {% set content %}
    <div class="table_box">
      <ul class="table_box">     
        {#{ decorators.riadok("Predmet:","<a href="~link~">"~row.predmetNazov~"</a>") }#}
        {{ decorators.riadok("Čas:",row.cas) }}
        {{ decorators.riadok("Dátum:",row.dat) }}
        {{ decorators.riadok("Miestnosť:",row.miestnosti) }}
        {{ decorators.riadok("Hodnotiaci:",row.hodnotiaci) }}
        {{ decorators.riadok("Počet prihlásených:",row.pocetPrihlasenych) }}
        {{ decorators.riadok("Maximálny počet:",row.maxPocet) }}
        {{ decorators.riadok("Poznámka:",row.poznamka) }}
        {{ decorators.riadok("Prihlasovanie:",row.prihlasovanie) }}
        {{ decorators.riadok("Odhlasovanie:",row.odhlasovanie) }}
        {{ decorators.riadok("Prihlás:", prihlas|raw) }}
        <li><a href={{link}} class="last">Zoznam prihlásenýh</a></li>
      </ul>      
    </div>
    {% endset %}      
    {{ decorators.collapsible(title, content, true) }}
  {% endmacro %}   

  {% set body %}
    {% for row in terminy %}      
        {% if row.mozeSaPrihlasit <= 0 %} {# moze sa prihlasit #}
          {% url form_action for {'action': 'studium.PrihlasNaSkusku',
                             'studium': studium,
                             'list': zapisnyList} %}
          {% set prihlas %}
            {# TODO(anty): update after those checks are moved to the model #}
            {% if row.mozeSaPrihlasit == constant("fajr\\controller\\studium\\MozePrihlasitNaTerminHelper::PRIHLASIT_MOZE_ZNAMKA") %}
              Už máš zapísané "{{ row.znamka }}"
            {% endif %}
            <form method='post' action='{{ form_action }}'>
              <div>
                <input type="hidden" name="prihlasPredmetIndex"
                       value="{{ row.predmetIndex }}" />
                <input type="hidden" name="prihlasTerminIndex"
                       value="{{ row.index }}" />
                <input type="hidden" name="hash" value="{{ row.hashNaPrihlasenie }}"/>
                <button name="submit" type="submit" class="tableButton positive">
                  <img src="images/third_party/silk/add.png" alt="" />Prihlás ma!
                </button>
              </div>
            </form>
          {% endset %}
        {% elseif row.mozeSaPrihlasit == constant("fajr\\controller\\studium\\MozePrihlasitNaTerminHelper::PRIHLASIT_NEMOZE_CAS") %}
          {% set prihlas="Nedá sa (mimo termínu prihlasovania)" %}
        {% elseif row.mozeSaPrihlasit == constant("fajr\\controller\\studium\\MozePrihlasitNaTerminHelper::PRIHLASIT_NEMOZE_POCET") %}
          {% set prihlas="Termín je plný" %}
        {% elseif row.mozeSaPrihlasit == constant("fajr\\controller\\studium\\MozePrihlasitNaTerminHelper::PRIHLASIT_NEMOZE_ZNAMKA") %}
          {% set prihlas %}Už máš zapísané "{{ row.znamka }}"{% endset %}
        {% else %}
          {% set prihlas="Nedá sa, dôvod neznámy" %}
        {% endif %}
        {{ _self.tabulkaTermin(row, prihlas, studium, zapisnyList, action) }}      
    {% endfor %}
  {% endset %}

  {% set title %}
    <h2>Termíny, na ktoré sa môžem prihlásiť</h2>
  {% endset %}

  {% set tableHTML %}
  {{ decorators.printbox(body, terminy|length == 0) }}
  {% endset %}

  {{ decorators.collapsible(title, tableHTML, false) }}

  {# ---- zoznam prihlasenych --- #}
  {{ studiumMacros.zoznamPrihlasenych(prihlaseni) }}

{% endset %}

{{ studiumMacros.studiumTabs(tabContent, 'ZapisSkusok', studium, zapisnyList) }}
{% endblock %}
